<?php

namespace zhtfrontend\models\datas;

use common\models\datas\Regions;
use Yii;

/**
 * This is the model class for table "{{%orders_address}}".
 *
 * @property integer $id
 * @property integer $orders_id
 * @property string $consignee
 * @property integer $province_id
 * @property integer $city_id
 * @property integer $district_id
 * @property string $address
 * @property string $mobile
 * @property string $zip
 * @property integer $receiving_time
 */
class OrdersAddress extends \zhtfrontend\components\bases\BaseModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%orders_address}}';
    }


    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['orders_id', 'province_id', 'city_id', 'district_id', 'receiving_time'], 'integer'],
            [['consignee', 'mobile', 'zip'], 'string', 'max' => 50],
            [['address'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('zhtfrontend', '自增编码'),
            'orders_id' => Yii::t('zhtfrontend', '订单id'),
            'consignee' => Yii::t('zhtfrontend', '收货人姓名'),
            'province_id' => Yii::t('zhtfrontend', '省'),
            'city_id' => Yii::t('zhtfrontend', '市'),
            'district_id' => Yii::t('zhtfrontend', '区'),
            'address' => Yii::t('zhtfrontend', '详细地址'),
            'mobile' => Yii::t('zhtfrontend', '手机号'),
            'zip' => Yii::t('zhtfrontend', '邮编'),
            'receiving_time' => Yii::t('zhtfrontend', '最佳收货时间'),
        ];
    }

    public function getProvince(){
        return $this->hasOne(Regions::className(),['region_id'=>'province_id']);
    }
    public function getCity(){
        return $this->hasOne(Regions::className(),['region_id'=>'city_id']);
    }
    public function getDistrict(){
        return $this->hasOne(Regions::className(),['region_id'=>'district_id']);
    }

}
